 package com.cxl.adt.queue;
 /* Location:           E:\work\eclipse3.6_\workspace\design_pattern\
  * Qualified Name:     com.cxl.adt.queue.Queue
  * JD-Core Version:    0.6.1
  */
public class Queue
 {
   private int maxSize;
   private long[] queArray;
   private int front;
   private int rear;
   private int nItems;
 
   public Queue(int s)
   {
     this.maxSize = s;
     this.queArray = new long[this.maxSize];
     this.front = 0;
     this.rear = -1;
     this.nItems = 0;
   }
 
   public void insert(long j)
   {
     if (this.rear == this.maxSize - 1) {
       this.rear = -1;
     }
     this.queArray[(++this.rear)] = j;
     this.nItems += 1;
   }
   public long remove() {
     long temp = this.queArray[(this.front++)];
     if (this.front == this.maxSize) {
       this.front = 0;
     }
     this.nItems -= 1;
     return temp;
   }
 
   public long peekFront() {
     return this.queArray[this.front];
   }
 
   public boolean isEmpty() {
     return this.nItems == 0;
   }
 
   public boolean isFull()
   {
     return this.nItems == this.maxSize;
   }
 
   public int size() {
     return this.nItems;
   }
 
   public static void main(String[] args) {
     Queue queue = new Queue(4);
     queue.insert(10L);
     queue.insert(20L);
     queue.insert(30L);
     queue.insert(40L);
 
     queue.insert(50L);
     queue.insert(60L);
     queue.insert(70L);
     queue.insert(80L);
 
     for (long s : queue.queArray) {
       System.out.print(s + ",");
     }
 
     while (!queue.isEmpty())
       System.out.println(queue.remove());
   }
 }